package com.jf.cloud.service.sysmanager.config;

import java.nio.charset.Charset;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.jf.cloud.service.sysmanager.support.SessionInterceptor;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Date: 2017/9/9
 * Time: 14:23
 * Description:
 */
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {

    @Autowired
    private SessionInterceptor sessionInterceptor;    

    /**
     * 根指向
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
    	registry.addViewController("/").setViewName("welcome");

        // 路由维护
        registry.addViewController("/systemRouter/list").setViewName("jsp/system/router_list");
        registry.addViewController("/systemRouter/toAddRouter").setViewName("jsp/system/router_add");
        
        // 修改密码
        registry.addViewController("/staff/passwordUpdate").setViewName("jsp/system/staff_pwd_update");
        
        // 基础类型维护
        registry.addViewController("/baseType/list").setViewName("jsp/base/baseType_list");
        registry.addViewController("/baseType/toAddBaseType").setViewName("jsp/base/baseType_add");
        registry.addViewController("/baseType/smallTypelist").setViewName("jsp/base/baseSmallType_list");
        registry.addViewController("/baseType/toAddBaseSmallType").setViewName("jsp/base/baseSmallType_add");
        
        // 运营商
        registry.addViewController("/baseOperator/list").setViewName("jsp/game/gameOperator_list");
        registry.addViewController("/baseOperator/toAddGameOperator").setViewName("jsp/game/gameOperator_add");
        
        // 游戏、游戏区、游戏服
        registry.addViewController("/game/list").setViewName("jsp/game/game_list");
        registry.addViewController("/game/toAddGame").setViewName("jsp/game/game_add");
        registry.addViewController("/gameArea/list").setViewName("jsp/game/gameArea_list");
        registry.addViewController("/gameArea/toAddGameArea").setViewName("jsp/game/gameArea_add");
        registry.addViewController("/gameServer/list").setViewName("jsp/game/gameServer_list");
        registry.addViewController("/gameServer/toAddGameServer").setViewName("jsp/game/gameServer_add");
        
        // 焦点图
        registry.addViewController("/foucsImg/list").setViewName("jsp/system/foucsImg_list");
        registry.addViewController("/foucsImg/toAddFoucsImg").setViewName("jsp/system/foucsImg_add");

        // 攻略
        registry.addViewController("/raiderManage/getRaiderManageList").setViewName("jsp/strategy/strategy_list");
        registry.addViewController("/raiderManage/toAddRaiderManage").setViewName("jsp/strategy/strategy_add");
        registry.addViewController("/raiderType/getRaiderTypeSmallList").setViewName("jsp/strategy/strategyTypeSmall_list");
        registry.addViewController("/raiderType/getRaiderTypeList").setViewName("jsp/strategy/strategyType_list");
        registry.addViewController("/raiderType/toAddRaiderType").setViewName("jsp/strategy/strategyType_add");

        //APP内嵌h5页面
        registry.addViewController("/strategyInfo").setViewName("h5/strategy_detail"); // 攻略详情
        registry.addViewController("/noticeInfo").setViewName("h5/notice_detail"); // 公告详情
        registry.addViewController("/mapInfo").setViewName("h5/map_detail"); // 地图详情
        registry.addViewController("/helpInfo").setViewName("h5/help_detail"); // 帮助详情
        registry.addViewController("/compound").setViewName("h5/compound"); //装备合成
        registry.addViewController("/compound_detail").setViewName("h5/compound_detail");
        registry.addViewController("/compound_property").setViewName("h5/compound_property");
        registry.addViewController("/czpage").setViewName("h5/czpage");
        registry.addViewController("/compound_search").setViewName("h5/compound_search");
        registry.addViewController("/pubGoodsInit").setViewName("h5/pub_goods_init"); // 商品发布初始页面
        registry.addViewController("/pubGoodsEditInit").setViewName("h5/pub_goods_edit_init"); // 商品编辑初始页面
        registry.addViewController("/pubGoodsJs").setViewName("h5/pub_goods_js"); // 寄售游戏币发布
        registry.addViewController("/pubGoodsZbJs").setViewName("h5/pub_goods_zb_js"); // 寄售装备发布
        registry.addViewController("/pubGoodsDb").setViewName("h5/pub_goods_db"); // 担保游戏币发布
        registry.addViewController("/pubGoodsZbDb").setViewName("h5/pub_goods_zb_db"); // 担保装备发布
        registry.addViewController("/order_detail").setViewName("h5/order_detail"); // 订单详情
     // roway 2018-01-08 交易商品详情、购买页面
        registry.addViewController("/buy/goodsList/view").setViewName("h5/products_detail");
        registry.addViewController("/buy_order/fillOrder_ml").setViewName("h5/submit_order");
        // 流放之路技术支持网站
        registry.addViewController("/LFZLSupport").setViewName("h5/lfzhl/index");

        // 地图
        registry.addViewController("/gameMaps/list").setViewName("jsp/game/gameMap_list");
        registry.addViewController("/gameMaps/toAddGameMap").setViewName("jsp/game/gameMap_add");
        registry.addViewController("/gameMapType/list").setViewName("jsp/game/gameMapType_list");
        registry.addViewController("/gameMapType/toAddGameMapType").setViewName("jsp/game/gameMapType_add");
        registry.addViewController("/gameMapLevel/list").setViewName("jsp/game/gameMapLevel_list");
        registry.addViewController("/gameMapLevel/toAddGameMapLevel").setViewName("jsp/game/gameMapLevel_add");

        // 物品
        registry.addViewController("/gameGoodsType/list").setViewName("jsp/goods/gameGoodsType_list");
        registry.addViewController("/gameGoodsType/toAddGoodsType").setViewName("jsp/goods/gameGoodsType_add");
        registry.addViewController("/gameGoodsType/smallTypelist").setViewName("jsp/goods/gameGoodsSmallType_list");
        registry.addViewController("/gameGoodsType/toAddGoodsSmallType").setViewName("jsp/goods/gameGoodsSmallType_add");

        // 物品置换
        registry.addViewController("/gameGoodsSwap/list").setViewName("jsp/goods/gameGoodsSwap_list");
        registry.addViewController("/gameGoodsSwap/toAddGoodsSwap").setViewName("jsp/goods/gameGoodsSwap_add");

        // 帮助文档
        registry.addViewController("/baseHelpDoc/list").setViewName("jsp/system/baseHelpDoc_list");
        registry.addViewController("/baseHelpDoc/toAddBaseHelpDoc").setViewName("jsp/system/baseHelpDoc_add");

        // roway 联系我们
        registry.addViewController("/contactOffical/list").setViewName("jsp/system/contactOffical_list");
        registry.addViewController("/contactOffical/toAdd").setViewName("jsp/system/contactOffical_add");

        //公告
        registry.addViewController("/baseAffiche/list").setViewName("jsp/system/baseAffiche_list");
        registry.addViewController("/baseAffiche/toAdd").setViewName("jsp/system/baseAffiche_add");

        // 用户管理
        registry.addViewController("/userInfo/list").setViewName("jsp/user/userInfo_list");
        
        // 装备合成 相关
        registry.addViewController("/gameEquipSlot/list").setViewName("jsp/equip/gameEquipSlot_list"); // 插槽列表
        registry.addViewController("/gameEquipSlot/toAddEquipSlot").setViewName("jsp/equip/gameEquipSlot_add"); // 插槽 添加
        registry.addViewController("/gameEquipAffix/list").setViewName("jsp/equip/gameEquipAffix_list"); // 词缀 列表
        registry.addViewController("/gameEquipAffix/toAddEquipAffix").setViewName("jsp/equip/gameEquipAffix_add"); // 词缀 添加
        registry.addViewController("/gameEquipType/list").setViewName("jsp/equip/gameEquipType_list"); // 装备类型列表
        registry.addViewController("/gameEquipType/toAddEquipType").setViewName("jsp/equip/gameEquipType_add"); // 装备类型 添加
        registry.addViewController("/gameEquipType/listEquip").setViewName("jsp/equip/gameEquipTypeSmall_list"); // 装备小类列表
        registry.addViewController("/gameEquipType/toAddEquipSmallType").setViewName("jsp/equip/gameEquipTypeSmall_add"); // 装备小类 添加
        registry.addViewController("/gameEquipLevel/list").setViewName("jsp/game/gameEquipLevel_list"); // 装备品阶列表
        registry.addViewController("/gameEquipLevel/toAdd").setViewName("jsp/game/gameEquipLevel_add"); // 装备品阶 添加
        registry.addViewController("/gameEquipLevelRelation/list").setViewName("jsp/game/gameEquipLevelRelation_list"); // 品阶关系列表
        registry.addViewController("/gameEquipLevelRelation/toAdd").setViewName("jsp/game/gameEquipLevelRelation_add"); // 品阶关系 添加
        registry.addViewController("/gameEquipManage/list").setViewName("jsp/game/gameEquipManage_list"); // 合成器装备管理列表
        registry.addViewController("/gameEquipManage/toAdd").setViewName("jsp/game/gameEquipManage_add"); // 合成器装备 添加
        registry.addViewController("/gameEquipMaster/list").setViewName("jsp/game/gameEquipMaster_list"); // 大师工艺列表
        registry.addViewController("/gameEquipMaster/toAdd").setViewName("jsp/game/gameEquipMaster_add"); // 大师工艺 添加
        registry.addViewController("/gameEquipRequiredGoods/list").setViewName("jsp/game/gameEquipRequiredGoods_list"); // 所需物品列表页面
        registry.addViewController("/gameEquipRequiredGoods/toAdd").setViewName("jsp/game/gameEquipRequiredGoods_add"); // 所需物品添加页面

        // 交易相关
        registry.addViewController("/tradeReasons/list").setViewName("jsp/trade/tradeReasons_list"); // 原因列表
        registry.addViewController("/tradeReasons/toAdd").setViewName("jsp/trade/tradeReasons_add"); // 原因 添加
        registry.addViewController("/basePublishNum/list").setViewName("jsp/trade/basePublishNum_list"); // 发布件数列表
        registry.addViewController("/basePublishNum/toAdd").setViewName("jsp/trade/basePublishNum_add"); // 发布件数 新增
        registry.addViewController("/tradeGoods/list").setViewName("jsp/trade/tradeGoods_list"); // 商品列表
        registry.addViewController("/tradeGoodsAudit/list").setViewName("jsp/trade/tradeGoodsAudit_list"); // 商品审核列表
        registry.addViewController("/tradeGoodsAudit/toChooseReason").setViewName("jsp/trade/tradeGoodsToChooseReason"); // 商品审核不通过原因选择页面
        registry.addViewController("/tradeGoodsAudit/toViewImg").setViewName("jsp/trade/tradeGoodsViewImg"); // 商品审核查看图片
        registry.addViewController("/tradeOrdersCx/list").setViewName("jsp/trade/tradeOrdersCx_list"); // 订单查询列表
        registry.addViewController("/tradeOrdersClJs/list").setViewName("jsp/trade/tradeOrdersClJs_list"); // 订单处理列表(寄售)
        registry.addViewController("/tradeOrdersClDb/list").setViewName("jsp/trade/tradeOrdersClDb_list"); // 订单处理列表(担保)
        registry.addViewController("/tradeOrdersCl/orderDetail").setViewName("jsp/trade/tradeOrderClDetail"); // 订单处理--订单详情页面
        registry.addViewController("/baseGameTradeFs/config").setViewName("jsp/trade/baseGameTradeFs_config"); // 游戏交易方式维护
        registry.addViewController("/baseAccountSafety/config").setViewName("jsp/trade/baseAccountSafety_config"); // 到账时间配置
        registry.addViewController("/baseAccountSafety/toAdd").setViewName("jsp/trade/baseAccountSafety_add"); // 到账时间配置添加页面
        registry.addViewController("/baseTradeSxFee/config").setViewName("jsp/trade/baseTradeSxFee_config"); // 手续费配置列表
        registry.addViewController("/baseTradeSxFee/toAdd").setViewName("jsp/trade/baseTradeSxFee_add"); // 手续费配置 新增
        registry.addViewController("/basePublishGoodsDesc/config").setViewName("jsp/trade/basePublishGoodsDesc_config"); // 商品描述配置列表
        registry.addViewController("/basePublishGoodsDesc/toAdd").setViewName("jsp/trade/basePublishGoodsDesc_add"); // 商品描述配置 新增
        
        // 财务管理
        registry.addViewController("/fundFinDrawWay/list").setViewName("jsp/fund/fundFinDrawWay_list"); // 提现方式列表
        registry.addViewController("/fundFinDrawWay/toAdd").setViewName("jsp/fund/fundFinDrawWay_add"); // 提现方式 添加
        registry.addViewController("/tradeFinDrawDetailCl/list").setViewName("jsp/fund/tradeFinDrawDetailCl_list"); // 提现订单处理列表
        registry.addViewController("/tradeFinDrawDetailCx/list").setViewName("jsp/fund/tradeFinDrawDetailCx_list"); // 提现订单查询列表
        registry.addViewController("/fundFinanceManualDetail/list").setViewName("jsp/fund/financeManualDetail_list"); // 加减款管理列表
        registry.addViewController("/fundFinanceMoneyFlowDetail/list").setViewName("jsp/fund/fundFinanceMoneyFlowDetail_list"); // 资金明细管理列表
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/common/**").addResourceLocations("classpath:/common/");
//        registry.addResourceHandler("/advert/**").addResourceLocations("classpath:/advert/");
//        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/css/");
//        registry.addResourceHandler("/images/**").addResourceLocations("classpath:/images/");
//        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
//        registry.addResourceHandler("/fonts/**").addResourceLocations("classpath:/fonts/");
//        registry.addResourceHandler("/MP_verify_EmeQlrDpUR8SisyI.txt").addResourceLocations("classpath:/MP_verify_EmeQlrDpUR8SisyI.txt");
//        registry.addResourceHandler("/view/**").addResourceLocations("classpath:/META-INF/resources/jsp/");
//        super.addResourceHandlers(registry);
//    }

    /**
     * 拦截请求
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(sessionInterceptor).addPathPatterns("/**").excludePathPatterns("/wap/**").excludePathPatterns("/");
        super.addInterceptors(registry);
    }


    @Bean
    public HttpMessageConverter<String> responseBodyConverter() {
        StringHttpMessageConverter converter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
        return converter;
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        converters.add(responseBodyConverter());
    }
}